package com.zesionlee.server.controller

import com.zesionlee.server.entity.DBEntity
import com.zesionlee.server.result.Result
import com.zesionlee.server.service.DBService
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.web.bind.annotation.*


@RestController
@RequestMapping("/db")
@Tag(description = "数据库模块", name = "数据库模块")
@CrossOrigin("*")
class DbController(val dbService: DBService) {


    @PostMapping("/test")
    @Operation(summary = "测试数据库连接")
    fun testDB(@RequestBody dbEntity: DBEntity): Result<Unit> {
        dbService.testDB(dbEntity)
        return Result.successMsg("连接成功")
    }

    @GetMapping("/db-config")
    fun getDbConfig(): Result<DBEntity> {
        val dbEntity: DBEntity = dbService.getDbConfig()
        return Result.success(dbEntity)
    }

}